home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / misc / 40 / wizard.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-07-17  |  5.0 KB  |  195 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  2. /* wizard.c - version 1.0.3 */
  3.  
  4. /* wizard code - inspired by rogue code from Merlyn Leroy (digi-g!brian) */
  5.  
  6. #include "hack.h"
  7. extern struct monst *makemon();
  8.  
  9. #define    WIZSHOT        6    /* one chance in WIZSHOT that wizard will try magic */
  10. #define    BOLT_LIM    8    /* from this distance D and 1 will try to hit you */
  11.  
  12. char wizapp[] = "@DNPTUVXcemntx";
  13.  
  14. /* If he has found the Amulet, make the wizard appear after some time */
  15. amulet(){
  16.     register struct obj *otmp;
  17.     register struct monst *mtmp;
  18.  
  19.     if(!flags.made_amulet || !flags.no_of_wizards)
  20.         return;
  21.     /* find wizard, and wake him if necessary */
  22.     for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  23.         if(mtmp->data->mlet == '1' && mtmp->msleep && !rn2(40))
  24.         for(otmp = invent; otmp; otmp = otmp->nobj)
  25.             if(otmp->olet == AMULET_SYM && !otmp->spe) {
  26.             mtmp->msleep = 0;
  27.             if(dist(mtmp->mx,mtmp->my) > 2)
  28.                 pline(
  29.     "You get the creepy feeling that somebody noticed your taking the Amulet."
  30.                 );
  31.             return;
  32.             }
  33. }
  34.  
  35. wiz_hit(mtmp)
  36. register struct monst *mtmp;
  37. {
  38.     /* if we have stolen or found the amulet, we disappear */
  39.     if(mtmp->minvent && mtmp->minvent->olet == AMULET_SYM &&
  40.         mtmp->minvent->spe == 0) {
  41.         /* vanish -- very primitive */
  42.         fall_down(mtmp);
  43.         return(1);
  44.     }
  45.  
  46.     /* if it is lying around someplace, we teleport to it */
  47.     if(!carrying(AMULET_OF_YENDOR)) {
  48.         register struct obj *otmp;
  49.  
  50.         for(otmp = fobj; otmp; otmp = otmp->nobj)
  51.         if(otmp->olet == AMULET_SYM && !otmp->spe) {
  52.             if((u.ux != otmp->ox || u.uy != otmp->oy) &&
  53.                !m_at(otmp->ox, otmp->oy)) {
  54.  
  55.             /* teleport to it and pick it up */
  56.             mtmp->mx = otmp->ox;
  57.             mtmp->my = otmp->oy;
  58.             freeobj(otmp);
  59.             mpickobj(mtmp, otmp);
  60.             pmon(mtmp);
  61.             return(0);
  62.             }
  63.             goto hithim;
  64.         }
  65.         return(0);                /* we don't know where it is */
  66.     }
  67. hithim:
  68.     if(rn2(2)) {                /* hit - perhaps steal */
  69.  
  70.         /* if hit 1/20 chance of stealing amulet & vanish
  71.         - amulet is on level 26 again. */
  72.         if(hitu(mtmp, d(mtmp->data->damn,mtmp->data->damd))
  73.         && !rn2(20) && stealamulet(mtmp))
  74.         ;
  75.     }
  76.     else
  77.         inrange(mtmp);            /* try magic */
  78.     return(0);
  79. }
  80.  
  81. inrange(mtmp)
  82. register struct monst *mtmp;
  83. {
  84.     register schar tx,ty;
  85.  
  86.     /* do nothing if cancelled (but make '1' say something) */
  87.     if(mtmp->data->mlet != '1' && mtmp->mcan)
  88.         return;
  89.  
  90.     /* spit fire only when both in a room or both in a corridor */
  91.     if(inroom(u.ux,u.uy) != inroom(mtmp->mx,mtmp->my)) return;
  92.     tx = u.ux - mtmp->mx;
  93.     ty = u.uy - mtmp->my;
  94.     if((!tx && abs(ty) < BOLT_LIM) || (!ty && abs(tx) < BOLT_LIM)
  95.         || (abs(tx) == abs(ty) && abs(tx) < BOLT_LIM)){
  96.         switch(mtmp->data->mlet) {
  97.         case 'D':
  98.         /* spit fire in the direction of @ (not nec. hitting) */
  99.         buzz(-1,mtmp->mx,mtmp->my,sgn(tx),sgn(ty));
  100.         break;
  101.         case '1':
  102.         if(rn2(WIZSHOT)) break;
  103.         /* if you zapped wizard with wand of cancellation,
  104.         he has to shake off the effects before he can throw
  105.         spells successfully.  1/2 the time they fail anyway */
  106.         if(mtmp->mcan || rn2(2)) {
  107.             if(canseemon(mtmp))
  108.             pline("%s makes a gesture, then curses.",
  109.                 Monnam(mtmp));
  110.             else
  111.             pline("You hear mumbled cursing.");
  112.             if(!rn2(3)) {
  113.             mtmp->mspeed = 0;
  114.             mtmp->minvis = 0;
  115.             }
  116.             if(!rn2(3))
  117.             mtmp->mcan = 0;
  118.         } else {
  119.             if(canseemon(mtmp)){
  120.             if(!rn2(6) && !Invis) {
  121.                 pline("%s hypnotizes you.", Monnam(mtmp));
  122. #ifdef DGK
  123.     /* bug fix by ab@unido
  124.      */
  125.                 nomul(-(rn2(3) + 3));
  126. #else
  127.                 nomul(rn2(3) + 3);
  128. #endif DGK
  129.                 break;
  130.             } else
  131.                 pline("%s chants an incantation.",
  132.                 Monnam(mtmp));
  133.             } else
  134.                 pline("You hear a mumbled incantation.");
  135.             switch(rn2(Invis ? 5 : 6)) {
  136.             case 0:
  137.             /* create a nasty monster from a deep level */
  138.             /* (for the moment, 'nasty' is not implemented) */
  139.             (void) makemon((struct permonst *)0, u.ux, u.uy);
  140.             break;
  141.             case 1:
  142.             pline("\"Destroy the thief, my pets!\"");
  143.             aggravate();    /* aggravate all the monsters */
  144.             /* fall into next case */
  145.             case 2:
  146.             if (flags.no_of_wizards == 1 && rnd(5) == 0)
  147.                 /* if only 1 wizard, clone himself */
  148.                 clonewiz(mtmp);
  149.             break;
  150.             case 3:
  151.             if(mtmp->mspeed == MSLOW)
  152.                 mtmp->mspeed = 0;
  153.             else
  154.                 mtmp->mspeed = MFAST;
  155.             break;
  156.             case 4:
  157.             mtmp->minvis = 1;
  158.             break;
  159.             case 5:
  160.             /* Only if not Invisible */
  161.             pline("You hear a clap of thunder!");
  162.             /* shoot a bolt of fire or cold, or a sleep ray */
  163.             buzz(-rnd(3),mtmp->mx,mtmp->my,sgn(tx),sgn(ty));
  164.             break;
  165.             }
  166.         }
  167.         }
  168.         if(u.uhp < 1) done_in_by(mtmp);
  169.     }
  170. }
  171.  
  172. aggravate()
  173. {
  174.     register struct monst *mtmp;
  175.  
  176.     for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  177.         mtmp->msleep = 0;
  178.         if(mtmp->mfroz && !rn2(5))
  179.             mtmp->mfroz = 0;
  180.     }
  181. }
  182.  
  183. clonewiz(mtmp)
  184. register struct monst *mtmp;
  185. {
  186.     register struct monst *mtmp2;
  187.  
  188.     if(mtmp2 = makemon(PM_WIZARD, mtmp->mx, mtmp->my)) {
  189.         flags.no_of_wizards = 2;
  190.         unpmon(mtmp2);
  191.         mtmp2->mappearance = wizapp[rn2(sizeof(wizapp)-1)];
  192.         pmon(mtmp);
  193.     }
  194. }
  195.